cmake_minimum_required(VERSION 3.24)
project(GPT3Bot)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Disable clip examples and tests
set(CLIP_EXAMPLES OFF CACHE BOOL "Compile clip examples")
set(CLIP_TESTS OFF CACHE BOOL "Compile clip tests")

set(Boost_USE_STATIC_LIBS ON)
find_package(Boost REQUIRED)
if (Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS})
    link_directories(${Boost_LIBRARY_DIRS})
endif ()

find_package(CURL CONFIG REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(ftxui REQUIRED)
find_package(TBB REQUIRED)
if (WIN32)
    find_package(libproxy REQUIRED)
else ()
    find_package(unofficial-utf8proc CONFIG REQUIRED)
endif ()

add_executable(${PROJECT_NAME} main/main.cpp main/GPTMain.cpp main/GPTMain.h main/interface/util/PromptUtils.cpp main/interface/util/PromptUtils.h main/interface/util/SystemUtils.cpp main/interface/util/SystemUtils.h main/interface/model/Embedding.cpp main/interface/model/Embedding.h main/interface/data/Exchange.cpp main/interface/data/Exchange.h main/interface/util/CURLUtils.cpp main/interface/util/CURLUtils.h main/interface/network/Network.cpp main/interface/network/Network.h main/interface/cpp-terminal/platforms/conversion.hpp main/interface/cpp-terminal/platforms/platform.hpp main/interface/cpp-terminal/platforms/platform.cpp main/interface/cpp-terminal/platforms/input.cpp main/interface/cpp-terminal/platforms/macros.hpp main/interface/cpp-terminal/platforms/tty.cpp main/interface/cpp-terminal/platforms/terminfo.cpp main/interface/cpp-terminal/platforms/terminal.cpp main/interface/cpp-terminal/base.cpp main/interface/cpp-terminal/base.hpp main/interface/cpp-terminal/color.cpp main/interface/cpp-terminal/color.hpp main/interface/cpp-terminal/exception.hpp main/interface/cpp-terminal/input.cpp main/interface/cpp-terminal/input.hpp main/interface/cpp-terminal/prompt.cpp main/interface/cpp-terminal/prompt.hpp main/interface/cpp-terminal/terminal.cpp main/interface/cpp-terminal/terminal.hpp main/interface/cpp-terminal/terminfo.hpp main/interface/cpp-terminal/tty.hpp main/interface/cpp-terminal/window.cpp main/interface/cpp-terminal/window.hpp main/resources.rc main/interface/util/TermUtils.cpp main/interface/util/TermUtils.h main/interface/network/APIKey.cpp main/interface/network/APIKey.h main/interface/util/TokenUtils.cpp main/interface/util/TokenUtils.h main/interface/cpp-terminal/platforms/inputU.cpp main/interface/cpp-terminal/inputU.hpp main/Command.cpp main/Command.h main/interface/data/Document.cpp main/interface/data/Document.h main/interface/util/FileUtils.cpp main/interface/util/FileUtils.h main/interface/network/Request.cpp main/interface/network/Request.h main/FineTuneHelper.cpp main/FineTuneHelper.h main/interface/model/FineTune.cpp main/interface/model/FineTune.h main/interface/storage/MemoryAdaptor.h main/interface/data/ExchangeHistory.cpp main/interface/data/ExchangeHistory.h main/Config.cpp main/Config.h main/interface/log/LogMsg.h main/interface/model/Completion.cpp main/interface/model/Completion.h main/interface/data/Messages.cpp main/interface/data/Messages.h main/interface/util/Base64.cpp main/interface/util/Base64.h main/interface/network/RequestObject.cpp main/interface/network/RequestObject.h main/Translator.cpp main/Translator.h)
add_subdirectory(main/interface/clip)
add_subdirectory(main/interface/cpp-tiktoken)

target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PRIVATE CURL::libcurl nlohmann_json::nlohmann_json ftxui::component TBB::tbb clip tiktoken)
if (WIN32)
    target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBPROXY_LIBRARIES})
else ()
    target_link_libraries(${PROJECT_NAME} PRIVATE utf8proc)
endif ()
if (NOT APPLE)
    if (UNIX)
        set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -lpthread")
    else ()
        set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -Wl,-Bstatic,--whole-archive -lpthread -Wl,-Bdynamic,--no-whole-archive")
    endif ()
endif ()
